USE Liberty
GO

-- ------------------------------------------------------------------------------------------------
-- Tasks Table Create Script
-- ------------------------------------------------------------------------------------------------
SET NOCOUNT OFF
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
GO

PRINT 'Creating Table dbo.Tasks...'
GO

IF OBJECT_ID('dbo.Tasks', 'U') IS NULL
BEGIN
	CREATE TABLE dbo.Tasks
	(OID					bigint		IDENTITY(1, 1)	NOT NULL
	,Version				rowversion
	,GrantID				bigint						NOT NULL
	,DueDate				smalldatetime				NOT NULL
	,ReminderDate			smalldatetime				NOT NULL
	,CompletedDate			smalldatetime					NULL
	,CompletedByUserID		bigint							NULL
	,ShortDescription		varchar(128)				NOT NULL
	,LongDescription		varchar(MAX)					NULL
	,UpdatedDate			datetime					NOT NULL
		CONSTRAINT DFLT_Tasks_UpdatedDate DEFAULT GETDATE()
	,CreatedDate			datetime					NOT NULL
		CONSTRAINT DFLT_Tasks_CreatedDate DEFAULT GETDATE()

	,CONSTRAINT PK_Tasks PRIMARY KEY CLUSTERED( OID ) --ON PRIMARY

	,CONSTRAINT FK_Tasks_Grants FOREIGN KEY (GrantID)
		REFERENCES Grants(OID)

 	,CONSTRAINT FK_Tasks_Users FOREIGN KEY (CompletedByUserID)
		REFERENCES Users(OID)

	)

	PRINT 'Table dbo.Tasks has been created successfully.'

END
ELSE 
BEGIN
    PRINT 'Table dbo.Tasks already exists.'
END

GO
